	// 获取支付通道
	function get_pay_channel(cb) {
		plus.payment.getChannels(function (paylist) {

			util.log("获取支付通道成功");
			util.log(JSON.stringify(paylist))
			var ali_pay = null;
			var wx_pay = null;
			// 必须从业务服务器获取支付信息
			for (var i = 0; i < paylist.length; i++) {
				if (paylist[i].id == 'alipay') {
					ali_pay = paylist[i]
				};
				if (paylist[i].id == 'wxpay') {
					wx_pay = paylist[i]
				}
			}
			util.log("cb-->" + JSON.stringify({
				wx_pay: wx_pay,
				ali_pay: ali_pay
			}))

			cb({
				wx_pay: wx_pay,
				ali_pay: ali_pay
			})
		}, function (err) {
			util.log(JSON.stringify(err));
		});
	}
	// 发起支付
	function pay(pay_type, pay_info, callback) {
		util.log("pay")
		if (!pay_type.serviceReady) {
			pay_type.installService();
		}

		plus.payment.request(pay_type, pay_info, function () {
			//							支付成功回调
			callback()

		}, function (e) {
//			alert("支付失败：" + e.message);
		mui.toast("支付失败")
		});

	}
	//获取支付凭证
	function get_wx_statement(order_info, callback) {
		// do ajax get statement...
		//				alert("url-->  "+ "https://zhapp.4hl.cn/app/Pay/getPrePayOrder");
		//				alert("order_no-->"+order_info.order_no)
		util.log("get_wx_statement")
		util.log("order_no-->" + order_info.order_no)
		mui.post("https://zhapp.4hl.cn/app/Pay/getPrePayOrder", {
			order_no: order_info.order_no
		}, function (res) {
			util.log(res);
			if (JSON.parse(res).code) {
				util.log(res);
			}

			callback(res)
		})

	}

	function get_ali_statement(order_info, callback) {
		// do ajax get statement...
		// 使用 order_info 请求后台支付数据
		var statement =
			'alipay_sdk=alipay-sdk-php-20161101&amp;app_id=2015112700878442&amp;biz_content=%7B%22body%22%3A%22DCloud%E8%87%B4%E5%8A%9B%E4%BA%8E%E6%89%93%E9%80%A0HTML5%E6%9C%80%E5%A5%BD%E7%9A%84%E7%A7%BB%E5%8A%A8%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7%EF%BC%8C%E5%8C%85%E6%8B%AC%E7%BB%88%E7%AB%AF%E7%9A%84Runtime%E3%80%81%E4%BA%91%E7%AB%AF%E7%9A%84%E6%9C%8D%E5%8A%A1%E5%92%8CIDE%EF%BC%8C%E5%90%8C%E6%97%B6%E6%8F%90%E4%BE%9B%E5%90%84%E9%A1%B9%E9%85%8D%E5%A5%97%E7%9A%84%E5%BC%80%E5%8F%91%E8%80%85%E6%9C%8D%E5%8A%A1%E3%80%82%22%2C%22subject%22%3A+%22DCloud%E9%A1%B9%E7%9B%AE%E6%8D%90%E8%B5%A0%22%2C%22out_trade_no%22%3A+%2220180729034701%22%2C%22timeout_express%22%3A+%2230m%22%2C%22total_amount%22%3A+%221%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%7D&amp;charset=UTF-8&amp;format=json&amp;method=alipay.trade.app.pay&amp;notify_url=http%253A%252F%252Fdemo.dcloud.net.cn%252Fpayment%252Falipay%252Fnotify.php&amp;sign_type=RSA2&amp;timestamp=2018-07-29+03%3A47%3A01&amp;version=1.0&amp;sign=AmvMfHmM2nMOXKAjangQo9%2FnXazSlmdqFhA5l9%2FRmeGb8KlfxcqLiJZT%2BWbwUgnvkSjpwlxsnWlcARTvME70WR0KOZNyks%2BsJ4%2FG2fAwE9afuvRIbH8CaS2T2zPF%2FdZvxoLLMQNnQjUAsaDpbVw2%2BITgfB6b8pFJxP%2F25%2BgFWMSy7UAM2Oueq64fl6A%2FVwQkjB0pI47ZAdF%2FdRHqp1scbmUoy%2B%2BkhdAxs7VFkvA8nY5QEAGZdD0G2iDH5oqjwM9FioNxbliG0qjnQ%2FwuRlC1nX6mRbTBqxac%2FAwEDHquZc1GE8JD4pdTL%2BII8Sag09KgBl%2FCTwl2zpO2s04VJRufdw%3D%3D'
		callback(statement)
	}


	//付款
	function pay_fun(that, k) {
		util.log("开始支付")
		// 		列表页的付款传过来k
		// 		直接下单的付款 直接传订单号过来
		
		// 将K转化为String 以防0为判断为false
		k = k + "";
		
		get_pay_channel(function (paylist) {
			// 获取支付通道成功回调	
			// 创建订单信息
			var order_info = {}
			// 如果K不存在,就变成了字符串undefined,所以这里用字符串判断
			if (k!="undefined"&&k!="group") {
				order_info = that.list[k]
			} else {
				order_info.order_no = that
			}
			
			util.log("order_info-->"+JSON.stringify(order_info))
			get_wx_statement(order_info, function (statement) {
				// 获取微信支付凭证回调
				pay(paylist.wx_pay, statement, function () {
					mui.alert("支付成功")
					util.log("支付成功");
					util.log('发起成功回调-->' + 'https://zhapp.4hl.cn/app/Pay/notify_urls');
					util.log("订单号-->" + order_info.order_no);
					util.log('状态-->1')
					$.ajax({
						url: "https://zhapp.4hl.cn/app/Pay/notify_urls",
						type: 'post',
						data: {
							order_no: order_info.order_no,
							status: '1'
						},
						success: function (res) {
							util.log(JSON.stringify(res))
							if(k!="undefined"){ // 订单列表付款
								
							}else{ // 直接付款
								
							}
							
							if(k=='group'){
								mui.openWindow('group_order_list.html', 'group_order_list.html');
								return
							}else{
								
								mui.openWindow('order_list.html?status=2', 'order_list.html');
								return
							}
							mui.openWindow('index.html', 'index.html');
							
						},
						error: function (err) {
							util.log("服务器错误！");
							util.log(JSON.stringify(err))

						}
					})

				})
			})

		})
	}

	
